<template>
  <views class="my_account_detail">
    <viewTitle :title="'账户详情'" :border="false"></viewTitle>
    <!-- 搜索-企业端-代理商 -->
      <div class="enterprise_search flex flexC">
        <el-form ref="form" label-width="auto" :inline="true">
        <div class="enterprise_search_input flex flexR center">
          <div class="order_number flex flexR center">
            <el-form-item label="业务订单号:">
              <el-input v-model="form.enterprise_order_sn" placeholder="业务订单号" :clearable="true"></el-input>
            </el-form-item>
          </div>
          <div class="batch_number flex flexR center">
            <el-form-item label="业务批次号:">
              <el-input
                v-model="form.enterprise_order_ext_sn"
                placeholder="业务批次号"
                :clearable="true"
              ></el-input>
            </el-form-item>
          </div>
          <div class="business_type flex flexR center">
            <el-form-item label="业务类型:">
              <el-select v-model="form.order_type" clearable placeholder="请选择">
                <el-option
                  v-for="item in business_type_list"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="business_type flex flexR center">
            <el-form-item label="交易状态:">
              <el-select v-model="form.payment_status" clearable placeholder="请选择">
                <el-option
                        v-for="item in payment_status_list"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </div>
        </div>
         </el-form>
        <el-form ref="form" label-width="auto" :inline="true">
        <div class="flex flexR search_btn">
          <div class="business_type flex flexR center">
            <el-form-item label="创建时间:">
              <el-date-picker
                v-model="creation_time"
                type="datetimerange"
                value-format="timestamp"
                align="right"
                :default-time="['0:00:00','23:59:59']"
                unlink-panels
                range-separator="至"
                @change="changeTime"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :picker-options="pickerOptions"
              ></el-date-picker>
            </el-form-item>
          </div>
           <el-form-item  >
          <div class="enterprise_search_btn flex flexR center">
            <el-button type="primary" @click="getData" icon="el-icon-search">查询</el-button>
            <el-button type @click="reset" icon="el-icon-refresh">重置</el-button>
            <el-button
              type="primary"
              :style="{width:140+'px'}"
              @click="exportExcel"
              size="medium"
              icon="el-icon-download"
            >导出列表</el-button>
          </div>
          </el-form-item>
        </div>
        </el-form>
      </div>

    <div class="search_input flex flexR center">
      <div :style="{marginLeft:'15px'}" class="show-title-money flex flexR">
        <div class="flex flexR">
          <div>交易笔数</div>
          <div class="price">{{pagination.total_count}}</div>
          <div>笔</div>
        </div>
        <div class="flex flexR">
          <div>交易金额(元)</div>
          <div class="price">￥{{pagination.summy ? $splitK(pagination.summy) : ''}}</div>
        </div>
      </div>
    </div>

    <!-- 表格-企业端 -->
    <div class="enterprise_table" v-if="this.$store.state.terrace==1">
      <el-table
        border
        :data="tableData"
        style="width: 100%;max-width:none;"
        :header-cell-style="getRowClass"
        :select-on-indeterminate="true"
        :fit="true"
        :lazy="true"
        @row-click="clickRow"
        max-height="450"
      >
        <el-table-column fixed type="index" label="序号" width="80"></el-table-column>
        <el-table-column prop="client_sn" label="客户编号" width="100"></el-table-column>
        <el-table-column prop="client_name" label="客户名称" width="120"></el-table-column>
        <el-table-column prop="enterprise_order_ext_sn" label="业务批次号" width="100"></el-table-column>
        <el-table-column prop="enterprise_order_sn" label="业务订单号" width="100"></el-table-column>
        <el-table-column prop :formatter="(row)=>{ return row.real_money == null ? '' : $splitK(row.real_money)}" label="交易金额" width="120"></el-table-column>
        <el-table-column
                :formatter="(row)=> {return this.status_list[row.payment_status];}"
                label="交易状态"
                width="120"
        ></el-table-column>
        <el-table-column prop :formatter="(row)=>{ return row.process_commission == null ? '' : $splitK(row.process_commission)}" label="交易手续费" width="150"></el-table-column>
        <el-table-column prop="op_type_name" label="业务类型" width="120"></el-table-column>
        <el-table-column prop :formatter="(row)=>{ return row.pre_balance == null ? '' : $splitK(row.pre_balance) }" label="账前余额" width="120"></el-table-column>
        <el-table-column prop :formatter="(row)=>{ return row.plat_money == null ? '': $splitK(row.plat_money)}" label="出/入账金额" width="120"></el-table-column>
        <el-table-column
          prop
          :formatter="(row)=>{ return $splitK(parseInt(row.op_type) == 1 ?  parseFloat(row.pre_balance) + parseFloat(row.plat_money) :   parseFloat(row.pre_balance) - parseFloat(row.plat_money))  }"
          label="账后余额"
          width="120"
        ></el-table-column>
        <el-table-column prop="created_time" label="创建时间" width="200"></el-table-column>
      </el-table>
    </div>
    <!-- 代理商表格 -->
    <div class="agent_table" v-if="this.$store.state.terrace==2">
      <el-table
        border
        :data="tableData"
        style="width: 100%;max-width:none;"
        :header-cell-style="getRowClass"
        :select-on-indeterminate="true"
        :fit="true"
        :lazy="true"
        @row-click="clickRow"
        max-height="450"
      >
        <el-table-column fixed type="index" label="序号" width="100"></el-table-column>
        <el-table-column fixed prop="enterprise_sn" label="客户编号" width="300"></el-table-column>
        <el-table-column prop="enterprise_name" label="客户名称" width="120"></el-table-column>
        <el-table-column prop="enterprise_order_ext_sn" label="业务批次号" width="300"></el-table-column>
        <el-table-column prop="enterprise_order_sn" label="业务订单号" width="300"></el-table-column>
        <el-table-column prop :formatter="(row)=>{ return row.trade_money == null ? '' : $splitK(row.trade_money)}" label="交易金额" width="120"></el-table-column>
        <el-table-column prop :formatter="(row)=>{ return row.trade_fee == null ? '' : $splitK(row.trade_fee)}" label="交易手续费" width="150"></el-table-column>
        <el-table-column prop="type" label="业务类型" width="120"></el-table-column>
        <el-table-column prop :formatter="(row)=>{ return row.pre_balance == null ? '' : $splitK(row.pre_balance)}"  label="账前余额" width="120"></el-table-column>
        <el-table-column prop :formatter="(row)=>{ return row.change_money == null ? '' : $splitK(row.change_money)}" label="出/入账金额" width="300"></el-table-column>
        <el-table-column prop :formatter="(row)=>{ return row.after_balance == null ? '' : $splitK(row.after_balance)}" label="账后余额" width="300"></el-table-column>
        <el-table-column prop="created_time" label="创建时间" width="300"></el-table-column>
      </el-table>
    </div>
    <!-- 服务商表格 -->
    <div class="agent_table" v-if="$store.state.terrace==3">
      <el-table
        border
        :data="tableData"
        style="width: 100%;max-width:none;"
        :header-cell-style="getRowClass"
        :select-on-indeterminate="true"
        :fit="true"
        :lazy="true"
        @row-click="clickRow"
        max-height="450"
      >
        <el-table-column fixed type="index" label="序号" width="100"></el-table-column>
        <el-table-column fixed prop="enterprise_sn" label="客户编号" width="300"></el-table-column>
        <el-table-column prop="enterprise_name" label="客户名称" width="150"></el-table-column>
        <el-table-column prop="enterprise_order_ext_sn" label="业务批次号" width="300"></el-table-column>
        <el-table-column prop="enterprise_order_sn" label="业务订单号" width="300"></el-table-column>
        <el-table-column prop :formatter="(row)=>{ return row.real_money==null ?  '' : $splitK(row.real_money) }" label="交易金额" width="120"></el-table-column>
        <el-table-column
          :formatter="(row)=> {return this.status_list[row.payment_status];}"
          label="交易状态"
          width="120"
        ></el-table-column>
        <el-table-column prop :formatter="(row)=>{ return row.process_commission == null ?  '' : $splitK(row.process_commission) }" label="交易手续费" width="150"></el-table-column>
        <el-table-column prop="order_type" label="业务类型" width="120"></el-table-column>
        <el-table-column prop :formatter="(row)=>{ return row.pre_balance == null ? '' : $splitK(row.pre_balance) }" label="账前余额" width="120"></el-table-column>
        <el-table-column prop :formatter="(row)=>{ return row.real_money == null ? '' :$splitK(row.real_money)}" label="出/入账金额" width="300"></el-table-column>
        <el-table-column prop :formatter="(row)=>{ return row.after_balance == null ? '' :$splitK(row.after_balance)}" label="账后余额" width="300"></el-table-column>
        <el-table-column prop="created_time" label="创建时间" width="300"></el-table-column>
      </el-table>
    </div>
    <div class="paging flex flexR">
      <el-pagination
        style="background:#fff; padding:10px 0"
        background
        layout="total, sizes,prev, pager, next, jumper"
        @size-change="(page_size) => {this.pagination.page_size = page_size;this.getData()}"
        @current-change="(page_size) => {this.pagination.page_start = page_size;this.getData()}"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="pagination.page_size"
        :total="pagination.total_count"
        :current-page="pagination.current_page"
        :page-count="pagination.page_count"
      ></el-pagination>
    </div>
  </views>
</template>


<script>
export default {
  name: "",
  data() {
    return {
      download_url: "",
      pagination: {
        page_start: 0, //搜索开始页码
        current_page: 0, //当前页码
        page_count: 0, //总页数
        page_size: 10, //每页数量
        total_count: 0, //总数量
        summy:0         //总金额
      },
      business_type_list: [
        { value: "", label: "全部" },
        { value: "1", label: "充值" },
        { value: "2", label: "代发" }
      ], //  业务类型列表
      payment_status_list: [
          { value: "", label: "全部" },
          { value: "0", label: "待打款" },
          { value: "1", label: "打款中" },
          { value: "2", label: "打款失败" },
          { value: "3", label: "拒绝打款" },
          { value: "4", label: "打款成功" },
      ], //  交易状态
      form: {
        enterprise_order_sn: "", //  业务订单号
        enterprise_order_ext_sn: "", //  业务批次号
        order_type: "", //  业务类型
        payment_status: "", //  业务类型
        money_direction: "", //  业务类型
        created_time_start: "", //  创建时间
        created_time_end: "" //  创建时间
      }, //  表单
      creation_time: "", //  创建时间
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      },
      tableData: [],
      status_list: ["待打款", "打款中", "打款失败", "拒绝打款", "打款成功"]
    };
  },
  mounted() {
    this.$setRouteTitle();
    this.getData();
  },
  created() {},
  methods: {
    //    修改第一行样式
    getRowClass({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return "background: #FAFAFA ";
      } else {
        return "";
      }
    },
    //     点击单行
    clickRow(row, column, event) {
      console.log(row, column, event);
    },
    //    修改是否换行
    changeStyleRow(width) {
      let _width = width - 290 - 350 - 300 - 50 - 25;
      if (_width > 300) {
        this.marginLeft = 25;
      } else {
        this.marginLeft = 0;
      }
    },
    //  重置
    reset() {
      this.form.enterprise_order_sn = ""; //  业务订单号
      this.form.enterprise_order_ext_sn = ""; //  业务批次号
      this.form.order_type = ""; //  业务类型
      this.creation_time = []; //  创建时间
      this.form.created_time_start = ""; //  创建时间
      this.form.created_time_end = ""; //  创建时间
      this.form.payment_status = "";  //  交易状态
      this.getData();
    },
    //获取数据
    getEnterpriseData() {
      let { code, msg, data } = this.$api.sendSync(
        this.$mapapi.eAccountOrderList,
        this.form
      );
      if (code != 200 && code != 501) {
        this.$message.error(msg);
        this.tableData = [];
        return;
      }
      this.download_url = data.download_url || "";
      this.tableData = data.list || [];
      this.pagination = data.pagination;
    },
    getAgentData() {
      let { code, msg, data } = this.$api.sendSync(
        this.$mapapi.aacountDetail,
        this.form
      );
      if (code != 200 && code != 501) {
        this.$message.error(msg);
        this.tableData = [];
        return;
      }
      this.download_url = data.download_url || "";
      this.tableData = data.list || [];
      this.pagination = data.pagination;
    },
    getFacilitatorData() {
      if (this.$route.query.enterprise_id) {
        this.form.enterprise_id = this.$route.query.enterprise_id;
      } else {
        this.form.enterprise_id = 0;
      }
      let { code, msg, data } = this.$api.sendSync(
        this.$mapapi.fmyAccount,
        this.form
      );
      if (code != 200 && code != 501) {
        this.$message.error(msg);
        this.tableData = [];
        return;
      }
      this.download_url = data.download_url || "";
      this.tableData = data.list || [];
      this.pagination = data.pagination;
    },
    getData() {
      this.form.pagination = this.pagination;
      if (this.$store.state.terrace == 1) {
        this.getEnterpriseData();
      }
      if (this.$store.state.terrace == 2) {
        this.getAgentData();
      }
      if (this.$store.state.terrace == 3) {
        this.getFacilitatorData();
      }
    },
    //导出
    exportExcel() {
      this.$import_excal(this.download_url || "");
    },
    //时间转换
    changeTime() {
      if (this.creation_time) {
        this.form.created_time_start =  this.creation_time[0]/1000
        this.form.created_time_end =this.creation_time[1]/1000
      } else {
        this.form.created_time_start = "";
        this.form.created_time_end = "";
      }
    },

  }
};
</script>


<style lang="less"  :scope="true"  src="@/style/account/my_account_detail.less" >
</style>